Bug 590959 - Set child_has_focus flag properly (second try)
authorBenjamin Otte <otte@gnome.org>
Thu, 6 Aug 2009 14:25:20 +0000 (16:25 +0200)
committerBenjamin Otte <otte@gnome.org>
Wed, 12 Aug 2009 12:49:02 +0000 (14:49 +0200)
Previously, this flag wasn't cleared properly when the notebook lost
focus, but only when the notebook was focussed again later.
As this flag is only used to advance correctly focus pages by grabbing
focus to the new page after switching the page, this is not good.
In particular, it can cause a focus grab when programmatically switching
the notebook page and the focus is inside a completely different widget.

A previous attempt at this fix in
6e0af6c25225440263792a3cbecd8f4301e3def5 has been reverted in
dfe0c8c0ca4823c77fa71b0048f6454958170b4e because it didn't work
correctly.

gtk/gtknotebook.c

index aa1a5ade06884a4616ad88261882b06ed8440003..2c6a507a4c55daab6640bf7869a77c695a75c087 100644 (file)
@@ -3094,8 +3094,6 @@ static gint
 gtk_notebook_focus_in (GtkWidget     *widget,
                       GdkEventFocus *event)
 {
-  GTK_NOTEBOOK (widget)->child_has_focus = FALSE;
-
   gtk_notebook_redraw_tabs (GTK_NOTEBOOK (widget));
   
   return FALSE;
@@ -3978,6 +3976,8 @@ gtk_notebook_set_focus_child (GtkContainer *container,
            }
        }
     }
+  else
+    notebook->child_has_focus = FALSE;
 
   GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
 }
@@ -5799,9 +5799,14 @@ gtk_notebook_real_switch_page (GtkNotebook     *notebook,
                               GtkNotebookPage *page,
                               guint            page_num)
 {
+  gboolean child_has_focus;
+
   if (notebook->cur_page == page || !GTK_WIDGET_VISIBLE (page->child))
     return;
 
+  /* save the value here, changing visibility changes focus */
+  child_has_focus = notebook->child_has_focus;
+
   if (notebook->cur_page)
     gtk_widget_set_child_visible (notebook->cur_page->child, FALSE);
 
@@ -5818,7 +5823,7 @@ gtk_notebook_real_switch_page (GtkNotebook     *notebook,
    * element on the new page, if possible, or if not, to the
    * notebook itself.
    */
-  if (notebook->child_has_focus)
+  if (child_has_focus)
     {
       if (notebook->cur_page->last_focus_child &&
          gtk_widget_is_ancestor (notebook->cur_page->last_focus_child, notebook->cur_page->child))